﻿using BW.EatRabbit.API.Application.Commands.Processing;
using BW.EatRabbit.Domain;
using BW.EatRabbit.ErrorCode;
using BW.EatRabbit.Infrastructure.Interfaces;
using MediatR;

namespace BW.EatRabbit.API.Application.CommandHandlers.Processing
{
    public class ProcessingCreateCommandHandler : IRequestHandler<ProcessingCreateCommand, APIResult<int>>
    {
        private readonly IBaseRepository<Processing_Information> _processingRepository;
        public ProcessingCreateCommandHandler(IBaseRepository<Processing_Information> processingRepository)
        {
            _processingRepository = processingRepository;
        }
        public Task<APIResult<int>> Handle(ProcessingCreateCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();

            Processing_Information processing = new Processing_Information();
            processing.ProcessingTeam=request.ProcessingTeam;
            processing.Leader=request.Leader;
            processing.ProductionBatch=request.ProductionBatch;
            processing.Creator = request.UserNickname;
            _processingRepository.AddEntity(processing);
            result.Code = ResultCode.添加成功;
            result.Message = ResultCode.添加成功.ToString();

            return Task.FromResult(result);
        }
    }
}
